<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.3.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/blog/images/logo.svg" color="#222">

<link rel="stylesheet" href="/blog/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/blog/lib/font-awesome/css/font-awesome.min.css">


<script id="hexo-configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    hostname: new URL('https://guodh.gitee.io/blog').hostname,
    root: '/blog/',
    scheme: 'Pisces',
    version: '7.7.1',
    exturl: false,
    sidebar: {"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},
    copycode: {"enable":true,"show_result":true,"style":null},
    back2top: {"enable":true,"sidebar":false,"scrollpercent":false},
    bookmark: {"enable":false,"color":"#222","save":"auto"},
    fancybox: false,
    mediumzoom: false,
    lazyload: false,
    pangu: false,
    comments: {"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},
    algolia: {
      appID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    },
    localsearch: {"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},
    path: 'search.xml',
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}
  };
</script>

  <meta name="description" content="都知道Rocketmq中有ConsumerGroup的概念。在集群模式下，多台服务器配置相同的ConsumerGroup，能够使得每次只有一台服务器消费消息（注意，但不保证只消费一次，存在网络抖动的情况）。那么，笔者就很疑惑，Rocketmq是如何实现这个模式的？如何保证只有一台服务器消费？ 虽然答案很简单，但却是一个很好的带着问题看源码的机会。 RocketMq结构  从图中可以看到，MQ主要投">
<meta property="og:type" content="article">
<meta property="og:title" content="RocketMq中MessageQueue的分配">
<meta property="og:url" content="https://guodh.gitee.io/blog/2018/02/25/2018/rocketmq%E9%97%AE%E9%A2%98/index.html">
<meta property="og:site_name" content="蛋蛋的小屋">
<meta property="og:description" content="都知道Rocketmq中有ConsumerGroup的概念。在集群模式下，多台服务器配置相同的ConsumerGroup，能够使得每次只有一台服务器消费消息（注意，但不保证只消费一次，存在网络抖动的情况）。那么，笔者就很疑惑，Rocketmq是如何实现这个模式的？如何保证只有一台服务器消费？ 虽然答案很简单，但却是一个很好的带着问题看源码的机会。 RocketMq结构  从图中可以看到，MQ主要投">
<meta property="og:locale">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/RocketMq%E7%A4%BA%E6%84%8F%E5%9B%BE.png">
<meta property="og:image" content="https://olwr1lamu.qnssl.com/AMQP.png">
<meta property="article:published_time" content="2018-02-25T13:21:21.000Z">
<meta property="article:modified_time" content="2018-02-25T01:31:27.000Z">
<meta property="article:author" content="RunningEgg">
<meta property="article:tag" content="rocketmq">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://olwr1lamu.qnssl.com/RocketMq%E7%A4%BA%E6%84%8F%E5%9B%BE.png">

<link rel="canonical" href="https://guodh.gitee.io/blog/2018/02/25/2018/rocketmq%E9%97%AE%E9%A2%98/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>RocketMq中MessageQueue的分配 | 蛋蛋的小屋</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-meta">

    <div>
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">蛋蛋的小屋</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <p class="site-subtitle">来了就看看吧，没有刀剑只有故事</p>
  </div>

  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/blog/" rel="section"><i class="fa fa-fw fa-home"></i>Home</a>

  </li>
        <li class="menu-item menu-item-about">

    <a href="/blog/about/" rel="section"><i class="fa fa-fw fa-user"></i>About</a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/blog/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>Archives</a>

  </li>
        <li class="menu-item menu-item-book">

    <a href="/blog/book/" rel="section"><i class="fa fa-fw fa-archive"></i>book</a>

  </li>
  </ul>

</nav>
</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
      
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://guodh.gitee.io/blog/2018/02/25/2018/rocketmq%E9%97%AE%E9%A2%98/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/blog/images/avatar.gif">
      <meta itemprop="name" content="RunningEgg">
      <meta itemprop="description" content="写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="蛋蛋的小屋">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          RocketMq中MessageQueue的分配
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">Posted on</span>
              

              <time title="Created: 2018-02-25 21:21:21 / Modified: 09:31:27" itemprop="dateCreated datePublished" datetime="2018-02-25T21:21:21+08:00">2018-02-25</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>都知道Rocketmq中有ConsumerGroup的概念。在集群模式下，多台服务器配置相同的ConsumerGroup，能够使得每次只有一台服务器消费消息（注意，但不保证只消费一次，存在网络抖动的情况）。那么，笔者就很疑惑，Rocketmq是如何实现这个模式的？如何保证只有一台服务器消费？</p>
<p>虽然答案很简单，但却是一个很好的带着问题看源码的机会。</p>
<h2 id="RocketMq结构"><a href="#RocketMq结构" class="headerlink" title="RocketMq结构"></a>RocketMq结构</h2><img src="https://olwr1lamu.qnssl.com/RocketMq%E7%A4%BA%E6%84%8F%E5%9B%BE.png" alt="RocketMQ架构示意图"/>

<p>从图中可以看到，MQ主要投递消息和拉取消息两个环节。</p>
<p>众多的架构都是顺应时代潮流而来，Rocketmq的结构体系当然也不是阿里所独创的，而是依据AMQP协议而来。Rocketmq中的Producer，Broker，以及Consumer都是依据AMQP中的概念衍生出来的。所以这里不妨讲讲AMQP（Advanced Message Queuing Protocal，高级消息队列协议），便于大家更好的理解技术的发展过程。</p>
<blockquote>
<p>paper下载 <a href="http://www.amqp.org/specification/0-9-1/amqp-org-download">http://www.amqp.org/specification/0-9-1/amqp-org-download</a> </p>
</blockquote>
<ul>
<li>Broker: 接收和分发的应用</li>
<li>Virtual host:出于多租户和安全因素，把AMQP的基本组件划分到一个虚拟分组中。各个租户之间是网络隔离的，类似Linux中的namespace概念（可自行Google）</li>
<li>Connection：publisher/consumer 和broker之间的TCP连接</li>
<li>Channel：是相较于Connection更加轻量的连接，是Connection上的逻辑连接</li>
<li>Exchange: 负责将message分发到不同的Queue中</li>
<li>Queue: 消息最终会落到Queue中，消息由Broker push给Consumer或者由Consumer来pull消息</li>
<li>Binding：exchange和queue之间的消息路由策略</li>
</ul>
<img src="https://olwr1lamu.qnssl.com/AMQP.png" alt="AMQP架构示意图"/>

<h2 id="消息队列的3大类型"><a href="#消息队列的3大类型" class="headerlink" title="消息队列的3大类型"></a>消息队列的3大类型</h2><p>当然基于这样一个协议，不单单是RocketMq一个闪耀在消息队列选型中，还有不同的消息队列。</p>
<blockquote>
<p><a href="https://mp.weixin.qq.com/s/B1D-J_1wpaqj0sxcmaArbQ">https://mp.weixin.qq.com/s/B1D-J_1wpaqj0sxcmaArbQ</a></p>
</blockquote>
<p>主要分为了3大阵营:</p>
<ul>
<li>有Broker 重Topic流：kafka，JMS</li>
<li>有Broker 轻Topic流: RocketMQ</li>
<li>无Broker: ZeroMQ</li>
</ul>
<p>当然，如果熟悉了AMQP协议，你也可以选择自研一个消息队列</p>
<blockquote>
<p><a href="https://zhuanlan.zhihu.com/p/28967866">https://zhuanlan.zhihu.com/p/28967866</a></p>
</blockquote>
<p>了解了一些背景，来看下RocketMQ中消息的投递过程。还是那个具体的问题，RocketMQ是如何选择一个队列来投递的呢？</p>
<h2 id="Producer如何投递消息到不同队列"><a href="#Producer如何投递消息到不同队列" class="headerlink" title="Producer如何投递消息到不同队列"></a>Producer如何投递消息到不同队列</h2><p>这里提一下，RocketMq中所有关于生产者和消费者的代码都在client包下。打开源码，可以看到Procuder下有个selector包，看到这个包是不是感到就是它的感觉。</p>
<p>可以看到selector下的三个类都是实现了MessageQueueSelector，来看下MessageQueueSelector的代码。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">interface</span> <span class="title">MessageQueueSelector</span> </span>&#123;</span><br><span class="line">    <span class="function">MessageQueue <span class="title">select</span><span class="params">(<span class="keyword">final</span> List&lt;MessageQueue&gt; mqs, <span class="keyword">final</span> Message msg, <span class="keyword">final</span> Object arg)</span></span>;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MessageQueue</span> </span>&#123;</span><br><span class="line">	<span class="keyword">private</span> String topic;</span><br><span class="line">	<span class="keyword">private</span> String brokerName;</span><br><span class="line">	<span class="keyword">private</span> <span class="keyword">int</span> queueId;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>看一下哪里调用了MessageQueueSelector.select()，发现是DefaultMQProducerImpl，那么可以确认就是由MessageQueueSelector提供了选择哪个队列。</p>
<p>RocketMq提供了3种不同的选择队列方式:</p>
<ul>
<li>SelectMessageQueueByHash</li>
<li>SelectMessageQueueByMachineRoom</li>
<li>SelectMessageQueueByRandom</li>
</ul>
<h3 id="默认队列数量"><a href="#默认队列数量" class="headerlink" title="默认队列数量"></a>默认队列数量</h3><p>细心的同学肯定会问那么队列数量是无限大的吗？这个可以查阅RocketMq的使用手册，默认的队列数量是4 (defaultTopicQueueNums: 4)，当然你也可以选择自己配置。</p>
<p>同时不知道有没有同学找错地儿，笔者刚开始是找错地儿了，在TopicPublishInfo中也找到了个selectOneMessageQueue，代码如下。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">TopicPublishInfo</span></span>&#123;</span><br><span class="line">    <span class="comment">// 不同版本，代码有些不同，逻辑类似</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> MessageQueue <span class="title">selectOneMessageQueue</span><span class="params">(<span class="keyword">final</span> String lastBrokerName)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (lastBrokerName != <span class="keyword">null</span>) &#123;</span><br><span class="line">            <span class="keyword">int</span> index = <span class="keyword">this</span>.sendWhichQueue.getAndIncrement();</span><br><span class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; <span class="keyword">this</span>.messageQueueList.size(); i++) &#123;</span><br><span class="line">                <span class="keyword">int</span> pos = Math.abs(index++) % <span class="keyword">this</span>.messageQueueList.size();</span><br><span class="line">                MessageQueue mq = <span class="keyword">this</span>.messageQueueList.get(pos);</span><br><span class="line">                <span class="keyword">if</span> (!mq.getBrokerName().equals(lastBrokerName)) &#123;</span><br><span class="line">                    <span class="keyword">return</span> mq;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">else</span> &#123;</span><br><span class="line">            <span class="keyword">int</span> index = <span class="keyword">this</span>.sendWhichQueue.getAndIncrement();</span><br><span class="line">            <span class="keyword">int</span> pos = Math.abs(index) % <span class="keyword">this</span>.messageQueueList.size();</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">this</span>.messageQueueList.get(pos);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>查了下调用方发现是MQFaultStrategy，看来是Rocketmq消费失败时候，会将消息重新投递到不同的队列，这样在集群模式下能够保证分布到不同机器消费。（是不是还有疑惑，为什么能保证到不同机器，请往下看）</p>
<h2 id="Consumer如何从消息队列获取消息"><a href="#Consumer如何从消息队列获取消息" class="headerlink" title="Consumer如何从消息队列获取消息"></a>Consumer如何从消息队列获取消息</h2><p>这里是比较难理解的一步，首先查阅RocketMQ手册可以看到：</p>
<blockquote>
<p>RocketMQ 的 Consumer 都是从 Broker 拉消息来消费，但是为了能做到实时收消息，RocketMQ 使用长轮询方式，可以保证消息实时性同 Push 方式一致。返种长轮询方式类似亍 Web QQ 收収消息机制。请参考以下信息了解更多。<a href="http://www.ibm.com/developerworks/cn/web/wa-lo-comet/">http://www.ibm.com/developerworks/cn/web/wa-lo-comet/</a></p>
</blockquote>
<p>虽然解释的很详细，但是对新手还是不是很友好。简单的来说，就是使用长轮询，客户端发起请求和服务端先连接上，但是如果服务端没有数据，这是连接还是hold住，当有数据push给客户端的时候才关闭连接。这样不但保证了消费者不会被上游的消息打垮，也保证了消息的实时性。</p>
<p>那么还有个问题，Consumer如何从MessageQueue上拉取消息呢？是随机拉吗？</p>
<p>不妨来看下MQPullConsumer，DefaultMQPullConsumer就是继承于它。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">MQPullConsumer</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 拉消息,非阻塞</span></span><br><span class="line">    <span class="comment">// </span></span><br><span class="line">    <span class="comment">// @param mq from which message queue</span></span><br><span class="line">    <span class="comment">// @param subExpression 订阅的tag，只支持&quot;tag1 || tag2 || tag3&quot;</span></span><br><span class="line">    <span class="comment">// @param offset 标志位</span></span><br><span class="line">    <span class="comment">// @param maxNums 消费最大数量</span></span><br><span class="line">    <span class="function">PullResult <span class="title">pull</span><span class="params">(<span class="keyword">final</span> MessageQueue mq, <span class="keyword">final</span> String subExpression, <span class="keyword">final</span> <span class="keyword">long</span> offset,</span></span></span><br><span class="line"><span class="function"><span class="params">	    <span class="keyword">final</span> <span class="keyword">int</span> maxNums)</span> <span class="keyword">throws</span> MQClientException, RemotingException, MQBrokerException,</span></span><br><span class="line"><span class="function">	    InterruptedException</span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>可以看到MessageQueue是传进来的，这就比较尴尬了，实在无法理解是什么时候决定好从哪个队列拉取消息的。幸亏有万能的搜索引擎，</p>
<blockquote>
<p><a href="https://zhuanlan.zhihu.com/p/25140744">https://zhuanlan.zhihu.com/p/25140744</a></p>
</blockquote>
<p>RocketMq有专门的类AllocateMessageQueueStrategy.class，就藏在Client.Consumer.rebalance包下。</p>
<ul>
<li>AllocateMessageQueueAveragely</li>
<li>AllocateMessageQueueAveragelyByCircle</li>
<li>AllocateMessageQueueByConfig</li>
<li>AllocateMessageQueueByMachineRoom</li>
<li>AllocateMessageQueueConsistentHash</li>
</ul>
<p>每一次Consumer数量的变更，都会触发AllocateMessageQueueStrategy。也就是每一次Consumer拉取的队列都是固定好的。</p>
<p>现在，在回过头来看看第一张RocketMQ的架构图，是不是觉得画的很透彻。</p>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><ol>
<li>任何的框架都有它衍生变化的历史，了解架构变化的历史，才能更好的理解一个框架</li>
<li>好好研读使用手册，包含了很多架构的细节</li>
<li>带着问题去研读源码</li>
</ol>

    </div>

    
    
    

      <footer class="post-footer">
          <div class="post-tags">
              <a href="/blog/tags/rocketmq/" rel="tag"># rocketmq</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/blog/2018/01/28/2018/AQS%E6%BA%90%E7%A0%81%E7%90%86%E8%A7%A3/" rel="prev" title="AQS源码理解">
      <i class="fa fa-chevron-left"></i> AQS源码理解
    </a></div>
      <div class="post-nav-item">
    <a href="/blog/2018/03/03/2018/JVM%E7%BA%BF%E4%B8%8A%E9%97%AE%E9%A2%98%E6%8E%92%E6%9F%A5%E5%B7%A5%E5%85%B7/" rel="next" title="JVM线上问题排查工具">
      JVM线上问题排查工具 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  

  </div>


          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#RocketMq%E7%BB%93%E6%9E%84"><span class="nav-number">1.</span> <span class="nav-text">RocketMq结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E7%9A%843%E5%A4%A7%E7%B1%BB%E5%9E%8B"><span class="nav-number">2.</span> <span class="nav-text">消息队列的3大类型</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Producer%E5%A6%82%E4%BD%95%E6%8A%95%E9%80%92%E6%B6%88%E6%81%AF%E5%88%B0%E4%B8%8D%E5%90%8C%E9%98%9F%E5%88%97"><span class="nav-number">3.</span> <span class="nav-text">Producer如何投递消息到不同队列</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%BB%98%E8%AE%A4%E9%98%9F%E5%88%97%E6%95%B0%E9%87%8F"><span class="nav-number">3.1.</span> <span class="nav-text">默认队列数量</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Consumer%E5%A6%82%E4%BD%95%E4%BB%8E%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF"><span class="nav-number">4.</span> <span class="nav-text">Consumer如何从消息队列获取消息</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">5.</span> <span class="nav-text">总结</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">RunningEgg</p>
  <div class="site-description" itemprop="description">写下我的点点滴滴，写下我对这个世界的看法，还有我内心锁崇拜的技术</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/blog/archives/">
        
          <span class="site-state-item-count">89</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">24</span>
        <span class="site-state-item-name">tags</span>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="mailto:guodh_1@163.com" title="E-Mail → mailto:guodh_1@163.com" rel="noopener" target="_blank"><i class="fa fa-fw fa-envelope"></i>E-Mail</a>
      </span>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">RunningEgg</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> v5.3.0
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">Theme – <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a> v7.7.1
  </div>

        








      </div>
    </footer>
  </div>

  
  <script src="/blog/lib/anime.min.js"></script>
  <script src="/blog/lib/velocity/velocity.min.js"></script>
  <script src="/blog/lib/velocity/velocity.ui.min.js"></script>

<script src="/blog/js/utils.js"></script>

<script src="/blog/js/motion.js"></script>


<script src="/blog/js/schemes/pisces.js"></script>


<script src="/blog/js/next-boot.js"></script>




  















  

  

</body>
</html>
